$(function () {
    //加载所属银行、产品系列、适用产品、目标客群
    var productBank = $("#productBank");//所属银行
    var productSerie = $("#productSerie");//产品系列
    var productName = $("#productName");//适用产品
    var customType = $("#customType");//目标客群

    $.ajax({
        url: "getmodelindexSelect",
        type: "GET",
        dataType: "json",
        success: function (data) {
            if (data != null) {
                var allBankName = data.allBankName;			//所属银行
                var allSerie = data.allSerie;				//产品系列
                var allProductName = data.allProductName;	//适用产品
                var allCustomType = data.allCustomType;		//目标客群

                // console.log(allBankName);
                // console.log(allSerie);
                // console.log(allProductName);
                // console.log(allCustomType);


                // console.log("allBankName:"+allBankName.length);
                // console.log("allSerie:"+allSerie.length);
                // console.log("allProductName:"+allProductName.length);
                // console.log("allCustomType:"+allCustomType.length);


                productBank.html("");
                productSerie.html("");
                productName.html("");
                customType.html("");


                //向所属银行select传入数据
                var options = "<option value=\"0\">---全部---</option>";
                for (var i = 0; i < allBankName.length; i++) {
                    options += "<option value=\"" + allBankName[i].id + "\">" + allBankName[i].bankname + "</option>";
                }
                //向产品系列select传入数据
                var optionss = "<option value=\"0\">---全部---</option>";
                for (var i = 0; i < allSerie.length; i++) {
                    optionss += "<option value=\"" + allSerie[i].id + "\">" + allSerie[i].serieName + "</option>";
                }
                //向适用产品select传入数据
                var optionsss = "<option value=\"0\">---全部---</option>";
                for (var i = 0; i < allProductName.length; i++) {
                    optionsss += "<option value=\"" + allProductName[i].id + "\">" + allProductName[i].loanname + "</option>";
                }
                //向目标客群select传入数据
                var optionssss = "<option value=\"0\">---全部---</option>";
                for (var i = 0; i < allCustomType.length; i++) {
                    optionssss += "<option value=\"" + allCustomType[i].id + "\">" + allCustomType[i].typename + "</option>";
                }

                productBank.html(options);
                productSerie.html(optionss);
                productName.html(optionsss);
                customType.html(optionssss);
            }
        }
    })
})


//判断快审模型是否为空
function addmodelName() {
    var modelName = document.getElementById("modelName").value;
    if (modelName == "") {
        $("#redModelName").html("快审模型不能为空！");
        return;
    } else {
        $("#redModelName").html("");
    }
}


//判断银行别是否为空
function adddivision() {
    var division = document.getElementById("division").value;
    if (division == "") {
        $("#redDivision").html("银行别不能为空！");
        return;
    } else {
        $("#redDivision").html("");
    }
}


//判断初审最低核可比例是否为空
function addpercentageDown() {
    var percentageDown = document.getElementById("percentageDown").value;
    if (percentageDown == "") {
        $("#redPercentageDown").html("初审最低核可比例不能为空！");
        return;
    } else {
        $("#redPercentageDown").html("");
    }
}


//判断初审最低核可分是否为空
function addscoreDown() {
    var scoreDown = document.getElementById("scoreDown").value;
    if (scoreDown == "") {
        $("#redScoreDown").html("初审最低核可分不能为空！");
        return;
    } else {
        $("#redScoreDown").html("");
    }
}


//判断适用贷款类型是否为空
function addloanType() {
    var loanType = document.getElementById("loanType").value;
    if (loanType == "") {
        $("#redLoanType").html("适用贷款类型不能为空！");
        return;
    } else {
        $("#redLoanType").html("");
    }
}


//判断适用地区是否为空
function addarea() {
    var area = document.getElementById("area").value;
    if (area == "") {
        $("#redArea").html("适用地区不能为空！");
        return;
    } else {
        $("#redArea").html("");
    }
}



//新建模型
function addModel(){
    var modelName = $("#modelName").val();
    var bankid = $("#productBank").val();
    var division = $("#division").val();
    var seriesid = $("#productSerie").val();
    var product = $("#productName").val();
    var customType = $("#customType").val();
    var percentageDown = $("#percentageDown").val();
    var scoreDown = $("#scoreDown").val();
    var loanType = $("#loanType").val();
    var area = $("#area").val();

    if(modelName==""|bankid==0|division==""|seriesid==0|product==0|customType==0|percentageDown==0|scoreDown==0|loanType==""|area==""){
        alert("带*的问题不能为空")
        return;
    }
    $.ajax({
        url: "addModel",
        type: "post",
        async: true,
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: {
            modelName : $("#modelName").val(),
            bankid : $("#productBank").val(),
            division : $("#division").val(),
            seriesid : $("#productSerie").val(),
            product : $("#productName").val(),
            customType : $("#customType").val(),
            percentageDown : $("#percentageDown").val(),
            scoreDown : $("#scoreDown").val(),
            loanType : $("#loanType").val(),
            area : $("#area").val(),
        },
        //请求成功后，回调函数
        success: function (data) {
            if (data.addResult == 1) {
                alert("新建模型成功");
                loadPage('incremental/add_model.html');
            } else {
                alert("新建模型失败");
            }
        },
        error: function (data) {
            alert("新建模型失败");
        }
    })
}